function getDefChartOption(conf) {
	var defNewLineChartOption = {
		title: {
			x: 'center'
		},
		legend: {
			x: 'left',
			y: 'top'
		},
		backgroundColor: 'white',
		tooltip: function() {
			var result;
			if (conf.chartType == 'line-bar') {
				result = {
					trigger: 'axis',
					formatter: function(params) {
						var result = '';
						var name = '';
						for (var i = 0; i < params.length; i++) {
							var param = params[i];
							var reverse = param.series.reverse;
							if (i == 0) {
								name = param.name;
								result += name;
							}
							result += '<br/>' + param.seriesName + ':' + (param.data * (reverse ? -1 : 1));
						}
						return result;
					}
				}
			} else if (conf.chartType == 'chart-pie') {
				result = {
					trigger: 'item',
					formatter: function(params) {
						var name = params.name;
						var val = params.value;
						var percent = params.percent;
						var valPrefix = params.series.valPrefix;

						return name + ' : ' + val + ' ' + valPrefix + ' (' + percent + '%)';
					}
				}
			}
			return result;
		}(),
		toolbox: {
			x: 'right',
			show: true,
			feature: {
				exportData: {
					show: true,
					title: '导出数据',
					icon: 'resources/images/chart_export_data.png',
					onclick: function() {
						function getCsvByPie(seriesDatas) {
							var result = '';
							for (var i = 0; i < 2; i++) {
								var lines = [];
								for (var y = 0; y < seriesDatas.length; y++) {
									if (i == 0) {
										lines.push(seriesDatas[y].name);
									} else if (i == 1) {
										lines.push(seriesDatas[y].value);
									}
								}
								result += lines.join(',');
								if (i == 0) {
									result += '\n';
								}
							}
							return result;
						}

						var option = this.option;
						var chartType = option.chartType;
						var csv = '';
						if (chartType == 'chart-pie') {
							var seriesDatas = option.series[0].data;
							csv = getCsvByPie(seriesDatas);
						} else if (chartType == 'line-bar') {
							var xAxisData = option.xAxis[0].data;
							var series = option.series;
							var seriesNames = [''];
							for (var i = 0; i < series.length; i++) {
								var serie = series[i];
								seriesNames.push(serie.name);
							}
							csv += seriesNames.join(',');
							for (var i = 0; i < xAxisData.length; i++) {
								seriesNames = [xAxisData[i]];
								for (var y = 0; y < series.length; y++) {
									var serie = series[y];
									var reverse = serie.reverse
									var val = serie.data[i];
									seriesNames.push(reverse ? -val : val);
								}
								csv += ('\n' + seriesNames.join(','));
							}
						}
						var csvData = 'data:application/csv;charset=utf-8,\ufeff' + encodeURIComponent(csv);
						var link = document.createElement('a');
						link.download = '下载.csv';
						link.href = csvData;
						link.click();
					}
				}
			}
		},
		xAxis: [{
			type: 'category',
			axisLine: {
				onZero: false
			}
		}],
		yAxis: [],
		series: []
	};
	return defNewLineChartOption;
}


function newLineExtend(data) {
	var chartType = data.chartType;
	//标记是否含有柱状图
	var hasBar = false;
	var chartOption = $.extend(true, {}, getDefChartOption(data));
	var serie = {
		type: 'line',
		itemStyle: {
			normal: {
				borderWidth: '1px'
			}
		},
		smooth: true,
		symbol: 'none'
	};

	function buildYAxisParams(axis, model) {
		var formatFun,
			min = axis.min,
			max = axis.max,
			reverse = axis.reverse;

		if (reverse) { // 反转
			var tmpMax = -max,
				tmpMin = -min;
			min = tmpMax;
			max = tmpMin;
		}
		if (model == 'left') {
			formatFun = leftLabelFormatter;
		} else if (model == 'right') {
			formatFun = rightLabelFormatter;
		}

		var json = {
				type: 'value',
				name: axis.name,
				axisLabel: {
					formatter: formatFun
				},
				min: min,
				max: max
			}
			// if (!hasBar) {
			// 	json = $.extend(json, {
			// 		min: min,
			// 		max: max
			// 	});
			// }
			// if(axis.axisType == 'line'){
			// 	json = $.extend(json, {
			// 		min: min,
			// 		max: max
			// 	});
			// }

		return json;
	}

	function leftLabelFormatter(value) {
		return yAxisLabelFormatter(value, data.leftYAxis.reverse, data.leftYAxis.floatNum);
	}

	function rightLabelFormatter(value) {
		return yAxisLabelFormatter(value, data.rightYAxis.reverse, data.rightYAxis.floatNum);
	}

	function yAxisLabelFormatter(value, reverse, floatNum) {
		if ($.isNumeric(value)) { //判断是不是数字
			if (reverse) { //反向
				value = value * -1;
			}

			if (!floatNum || floatNum == '') {
				var valueStr = value.toString();
				var dokIndex = valueStr.indexOf('.');
				if (dokIndex != -1) {
					var valLen = valueStr.length;
					var douNum = (valLen - (dokIndex + 1));
					if (douNum >= 3) {
						value = value.toFixed(2);
					}
				}
			} else {
				value = value.toFixed(floatNum);
			}
		}
		return value;
	}



	var legendData = [];
	if (chartType == 'line-bar') {
		for (var i = 0; i < data.chartLineParams.length; i++) {
			var chartLineParam = data.chartLineParams[i];
			var newSerie = $.extend(true, {}, serie);
			var axisType = chartLineParam.axisType;
			if (axisType) { //定义chart类型
				newSerie.type = axisType;
				if (axisType == 'bar' && !hasBar) {
					hasBar = true;
				}
			}
			var reverse = false
			if (chartLineParam.axisOption == 'leftYAxis') {
				newSerie.yAxisIndex = 0;
				reverse = data.leftYAxis.reverse;
				data.leftYAxis.axisType = axisType;
			} else if (chartLineParam.axisOption == 'rightYAxis') {
				newSerie.yAxisIndex = 1;
				reverse = data.rightYAxis.reverse;
				data.rightYAxis.axisType = axisType;
			}
			newSerie.name = chartLineParam.axisName;
			if (reverse) { //特殊处理数据
				var colDatas = chartLineParam.colDatas;
				newSerie.data = (function() {
					var oriData = colDatas;
					var len = oriData.length;
					while (len--) {
						oriData[len] *= -1;
					}
					return oriData;
				})();
			} else {
				newSerie.data = chartLineParam.colDatas;
			}
			newSerie.reverse = reverse;
			chartOption.series.push(newSerie);
			legendData.push(chartLineParam.axisName);
		}
	} else if (chartType == 'chart-pie') {
		var newSerie = $.extend(true, {}, serie);

		var serieData = [];
		var sumVal = 0.0;
		for (var i = 0; i < data.chartLineParams.length; i++) {
			var line = data.chartLineParams[i];
			var value = line.colDatas[0][line.colIndex];
			sumVal += parseFloat(value);
		}

		for (var i = 0; i < data.chartLineParams.length; i++) {
			var line = data.chartLineParams[i];
			var name = line.axisName;
			var value = line.colDatas[0][line.colIndex];
			var valFloat = parseFloat(value);
			var subVal = valFloat / sumVal * 100;
			var lastName = name + "(" + (subVal.toFixed(2)) + "%)";
			serieData.push({
				value: valFloat,
				name: lastName
			});
			legendData.push(lastName);
		}
		chartOption.series.push({
			type: 'pie',
			radius: '45%',
			center: ['50%', '60%'],
			data: serieData,
			valPrefix: data.valPrefix
		});
		chartOption.calculable = true;
		chartOption.legend.orient = 'vertical';
		chartOption.valPrefix = data.valPrefix;

		delete chartOption.xAxis;
		delete chartOption.yAxis;
	}

	chartOption.chartType = chartType;

	chartOption.title.text = data.chartTitle;
	chartOption.legend.data = legendData;

	if (chartType == 'line-bar') {
		// chartOption.xAxis[0].name = data.xAxis.colName;
		chartOption.xAxis[0].data = data.xAxis.colDatas;
		// 两端是否留白 true 留白  false 不留白
		chartOption.xAxis[0].boundaryGap = hasBar;

		if (!$.isEmptyObject(data.leftYAxis)) { //左
			var axis = data.leftYAxis;
			chartOption.yAxis.push(buildYAxisParams(axis, 'left'));
		}

		if (!$.isEmptyObject(data.rightYAxis)) { //右
			var axis = data.rightYAxis;
			chartOption.yAxis.push(buildYAxisParams(axis, 'right'));
		}
	}


	return chartOption;
}